int KMP(char* text, char* pattern) {
    int n = strlen(text);
    int m = strlen(pattern);
    // 计算模式串的next数组
    int* next = (int*)malloc(sizeof(int) * m);
    next[0] = -1;
    int i = 0, j = -1;
    while (i < m - 1) {
        if (j == -1 || pattern[i] == pattern[j]) {
            i++;
            j++;
            next[i] = j;
        } else {
            j = next[j];
        }
    }
    // 使用next数组进行匹配
    i = 0;
    j = 0;
    while (i < n && j < m) {
        if (j == -1 || text[i] == pattern[j]) {
            i++;
            j++;
        } else {
            j = next[j];
        }
    }
    // 如果匹配成功，返回子字符串在文本串中的起始位置
    if (j == m) {
        return i - m;
    }
    // 否则返回-1
    return -1;
}

char** stringMatching(char** words, int wordsSize, int* returnSize) {
    char** res = (char**)malloc(sizeof(char*) * wordsSize);
    int resSize = 0;
    // 遍历所有单词
    for (int i = 0; i < wordsSize; i++) {
        char* word = words[i];
        // 在其它单词中进行匹配
        for (int j = 0; j < wordsSize; j++) {
            // 跳过与自己匹配
            if (i == j) {
                continue;
            }
            // 如果找到了子字符串位置，将该单词添加到结果数组中
            if (KMP(words[j], word) != -1) {
                res[resSize++] = word;
                break;
            }
        }
    }
    *returnSize = resSize;
    return res;
}